
/**
 * 检测时间区间是否有冲突
 */
function validateTime(data) {
  const timeList = data.map(item => item.timeRange)
  const date = new Date()
  let result = true
  const list = [] // 冲突项
  for (let i = 0; i < timeList.length; i++) { // 冒泡比较是否冲突
    if (!timeList[i][0]) continue
    date.setHours(timeList[i][0].split(':')[0])
    date.setMinutes(timeList[i][0].split(':')[1])
    const time1 = date.getTime()
    date.setHours(timeList[i][1].split(':')[0])
    date.setMinutes(timeList[i][1].split(':')[1])
    const time2 = date.getTime()
    for (let j = 0; j < i; j++) {
      if (!timeList[j][0]) continue
      date.setHours(timeList[j][0].split(':')[0])
      date.setMinutes(timeList[j][0].split(':')[1])
      const time3 = date.getTime()
      date.setHours(timeList[j][1].split(':')[0])
      date.setMinutes(timeList[j][1].split(':')[1])
      const time4 = date.getTime()
      if (!(time3 > time2 || time4 < time1)) {
        result = false
        list.push(i, j) // 记录用于页面标红
      }
    }
  }
  return { result, list }
}
export {
  validateTime
}
